package com.ttfeed.server.api.controller;

import com.ttfeed.server.api.domain.entity.RecentFeedRecord;
import com.ttfeed.server.api.domain.response.RecentFeedLatestRecordResp;
import com.ttfeed.server.api.domain.response.RecentFeedRecordListResp;
import com.ttfeed.server.api.service.RecentFeedRecordService;
import com.ttfeed.server.common.domain.base.ApiResult;
import com.ttfeed.server.common.domain.base.ListReq;
import com.ttfeed.server.common.domain.base.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/recent-feed-record")
public class RecentFeedRecordController {

    @Autowired
    private RecentFeedRecordService recentFeedRecordService;

    @PostMapping("/list")
    public ApiResult<PageResult<RecentFeedRecord>> list(@RequestBody ListReq listReq) {
        return ApiResult.success(recentFeedRecordService.getList(listReq));
    }

    @GetMapping("/latest/{type}")
    public ApiResult<RecentFeedLatestRecordResp> latest(@PathVariable("type")Integer type) {
        if(type > 1 || type < 0) {
            return ApiResult.fail("参数错误");
        }
        // 换尿布对应的typeId 1,2,3
        List<Integer> typeIdList = new ArrayList<>();
        if(type == 0) {
            typeIdList.add(1);
            typeIdList.add(2);
            typeIdList.add(3);
        }
        // 喂养对应的typeId 4
        if(type == 1) {
            typeIdList.add(4);
        }
        return ApiResult.success(recentFeedRecordService.getLatestRecordByTypeIdList(type, typeIdList));
    }
}
